
package org.bridgen.lang.semantics.ast;
import java.util.*;




public class IgnoreDecl extends Element implements Cloneable {
    public void flushCache() {
        super.flushCache();
    }
     @SuppressWarnings({"unchecked", "cast"})  public IgnoreDecl clone() throws CloneNotSupportedException {
        IgnoreDecl node = (IgnoreDecl)super.clone();
        node.in$Circle(false);
        node.is$Final(false);
    return node;
    }
     @SuppressWarnings({"unchecked", "cast"})  public IgnoreDecl copy() {
      try {
          IgnoreDecl node = (IgnoreDecl)clone();
          if(children != null) node.children = (ASTNode[])children.clone();
          return node;
      } catch (CloneNotSupportedException e) {
      }
      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
      return null;
    }
     @SuppressWarnings({"unchecked", "cast"})  public IgnoreDecl fullCopy() {
        IgnoreDecl res = (IgnoreDecl)copy();
        for(int i = 0; i < getNumChildNoTransform(); i++) {
          ASTNode node = getChildNoTransform(i);
          if(node != null) node = node.fullCopy();
          res.setChild(node, i);
        }
        return res;
    }
    // Declared in ParserCodeGen.jrag at line 99

	
	public void generateMethod_matchIgnore(String indent, StringBuffer buf) {
		buf.append(indent + "// " + getName() + "\n");
		buf.append(indent + "if (matchForward(content, curPos, " + className() + ".START_VALUE)) {\n");
		buf.append(indent + INDENT + "int endPos = ignoreUntil(content, curPos + " + className() + 
			".START_VALUE.length(), " + className() + ".END_VALUE);\n");
		buf.append(indent + INDENT + "Interval interval = new Interval(curPos, endPos);\n");
		buf.append(indent + INDENT + "return new " + className() + "(previous, interval, new String(content, curPos, \n"); 
		buf.append(indent + INDENT + INDENT + "(endPos < content.length - 1) ? interval.getLength() + 1 : interval.getLength()));\n");
		buf.append(indent + "}\n");	
	}

    // Declared in PrettyPrint.jrag at line 361

    
    
    public void pp(StringBuffer buf) {
    	buf.append(indent() + "ignore ");
    	getStart().pp(buf);
    	buf.append(" to ");
    	getEnd().pp(buf);
    	buf.append(";\n");
    }

    // Declared in TypeCodeGen.jrag at line 35

		
	// Code generation for ignode declarations
	
	public void generateCode(StringBuffer buf, String packageName) {
		String indent = INDENT;
		
		// Package
		if (packageName.trim().length() > 0) {
			buf.append("package " + packageName + ";\n\n");
		}
		
		// Imports
		buf.append("import org.briplib.recovery.*;\n");
		buf.append("import org.briplib.recovery.util.*;\n\n"); 
		
		// Class signature
		buf.append("public " + "class " + className() + " extends Ignore {\n\n");
		
		// Class attributes
		generateClassAttributes(indent, buf);
		
		// Constructor
		generateConstructor(indent, buf);
		
		// Methods
		generateMethods(indent, buf);
		
		buf.append("}\n");
	}

    // Declared in TypeCodeGen.jrag at line 62

	
	public void generateClassAttributes(String indent, StringBuffer buf) {
		buf.append(indent + "public static final String START_VALUE = \"" + getStart().value() + "\";\n");
		buf.append(indent + "public static final String END_VALUE = \"" + getEnd().value() + "\";\n");
	}

    // Declared in TypeCodeGen.jrag at line 69


	// Code generation of ignore constructors
	
	public void generateConstructor(String indent, StringBuffer buf) {
		// Basic constructor
		buf.append(indent + "public " + className() + 
			"(LexicalNode previous, Interval interval, String value) {\n");
		buf.append(indent + INDENT + "super(previous, interval, value);\n");
		buf.append(indent + "}\n\n");	
	}

    // Declared in TypeCodeGen.jrag at line 79

	
	// Generate methods
	
	public void generateMethods(String indent, StringBuffer buf) {
		generateMethod_clone(indent, buf);
	}

    // Declared in TypeCodeGen.jrag at line 85

	
	// Code generation of clone method
	
	public void generateMethod_clone(String indent, StringBuffer buf) {
		// Basic clone method
		buf.append(indent + "public LexicalNode clone(LexicalNode previous) {\n");
		buf.append(indent + INDENT + "return new " + className() + 
			"(previous, getInterval().clone(), value);\n");
		buf.append(indent + "}\n\n");
	}

    // Declared in bridgit.ast at line 3
    // Declared in bridgit.ast line 34

    public IgnoreDecl() {
        super();


    }

    // Declared in bridgit.ast at line 10


    // Declared in bridgit.ast line 34
    public IgnoreDecl(String p0, ValuePattern p1, ValuePattern p2) {
        setName(p0);
        setChild(p1, 0);
        setChild(p2, 1);
    }

    // Declared in bridgit.ast at line 16


  protected int numChildren() {
    return 2;
  }

    // Declared in bridgit.ast at line 19

  public boolean mayHaveRewrite() { return false; }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 34
    protected String tokenString_Name;

    // Declared in bridgit.ast at line 3

    public void setName(String value) {
        tokenString_Name = value;
    }

    // Declared in bridgit.ast at line 6

    public String getName() {
        return tokenString_Name != null ? tokenString_Name : "";
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 34
    public void setStart(ValuePattern node) {
        setChild(node, 0);
    }

    // Declared in bridgit.ast at line 5

    public ValuePattern getStart() {
        return (ValuePattern)getChild(0);
    }

    // Declared in bridgit.ast at line 9


    public ValuePattern getStartNoTransform() {
        return (ValuePattern)getChildNoTransform(0);
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 34
    public void setEnd(ValuePattern node) {
        setChild(node, 1);
    }

    // Declared in bridgit.ast at line 5

    public ValuePattern getEnd() {
        return (ValuePattern)getChild(1);
    }

    // Declared in bridgit.ast at line 9


    public ValuePattern getEndNoTransform() {
        return (ValuePattern)getChildNoTransform(1);
    }

    // Declared in TypeCodeGen.jrag at line 31
 @SuppressWarnings({"unchecked", "cast"})     public String className() {
        String className_value = className_compute();
        return className_value;
    }

    private String className_compute() {  return "Ignore" + getName();  }

public ASTNode rewriteTo() {
    return super.rewriteTo();
}

    protected void collect_contributors_Grammar_ignoreDecls() {
        // Declared in TypeCodeGen.jrag at line 26
        {
            Grammar ref = (Grammar)(enclosingGrammar());
            if(ref != null)
                ref.Grammar_ignoreDecls_contributors.add(this);
        }
        super.collect_contributors_Grammar_ignoreDecls();
    }
    protected void contributeTo_Grammar_Grammar_ignoreDecls(Collection collection) {
        super.contributeTo_Grammar_Grammar_ignoreDecls(collection);
        collection.add(this);
    }

}
